package org.example.spring.self.demo.pb;

import org.springframework.beans.factory.ObjectFactory;
import org.springframework.stereotype.Service;

/**
 * 文件描述
 *
 * @author yezhou41127
 * @date: 2022年09月01日
 */

@Service
public class MessageService2 {

	private final ObjectFactory<MessageBuilder> messageBuilder;

	MessageService2(ObjectFactory<MessageBuilder> messageBuilder) {
		this.messageBuilder = messageBuilder;
	}

	Message createMessage(String content, String receiver) {
		// getObject 重新生成对象
		return messageBuilder.getObject()
				.withContent(content)
				.withReceiver(receiver)
				.build();
	}

}
